]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
tests: Port Highlighter test to jasmine
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 20 Jan 2024 07:00:39 +0000 (08:00 +0100)
committerMarge Bot <marge-bot@gnome.org>
Tue, 21 May 2024 13:42:28 +0000 (13:42 +0000)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3164>

tests/meson.build
tests/unit/highlighter.js

index 0a3d2d7daa59992ac90ae8b88b0c055b6a02c95c..b9729d9dedcb324d906c036810c9f16a7456838d 100644 (file)
@@ -20,6 +20,7 @@ unit_testenv.append('GI_TYPELIB_PATH', shell_typelib_path, separator: ':')
 unit_testenv.append('GI_TYPELIB_PATH', st_typelib_path, separator: ':')
 
 unit_tests = [
+    'highlighter',
 ]
 
 foreach test : unit_tests
@@ -38,7 +39,6 @@ foreach test : unit_tests
 endforeach
 
 legacy_tests = [
-    'highlighter',
     'injectionManager',
     'insertSorted',
     'jsParse',
index 3c0d3f188e1a37c89a15804857775abebb280171..814c0093e700df713dc80f9dd2274244da65b2d8 100644 (file)
 
 // Test cases for SearchResult description match highlighter
 
-const JsUnit = imports.jsUnit;
 import Pango from 'gi://Pango';
 
 import 'resource:///org/gnome/shell/ui/environment.js';
-import * as Util from 'resource:///org/gnome/shell/misc/util.js';
+import {Highlighter} from 'resource:///org/gnome/shell/misc/util.js';
 
-const tests = [
-    {
-        input: 'abc cba',
-        terms: null,
-        output: 'abc cba',
-    },
-    {
-        input: 'abc cba',
-        terms: [],
-        output: 'abc cba',
-    },
-    {
-        input: 'abc cba',
-        terms: [''],
-        output: 'abc cba',
-    },
-    {
-        input: 'abc cba',
-        terms: ['a'],
-        output: '<b>a</b>bc cb<b>a</b>',
-    },
-    {
-        input: 'abc cba',
-        terms: ['a', 'a'],
-        output: '<b>a</b>bc cb<b>a</b>',
-    },
-    {
-        input: 'CaSe InSenSiTiVe',
-        terms: ['cas', 'sens'],
-        output: '<b>CaS</b>e In<b>SenS</b>iTiVe',
-    },
-    {
-        input: 'This contains the < character',
-        terms: null,
-        output: 'This contains the &lt; character',
-    },
-    {
-        input: 'Don\'t',
-        terms: ['t'],
-        output: 'Don&apos;<b>t</b>',
-    },
-    {
-        input: 'Don\'t',
-        terms: ['n\'t'],
-        output: 'Do<b>n&apos;t</b>',
-    },
-    {
-        input: 'Don\'t',
-        terms: ['o', 't'],
-        output: 'D<b>o</b>n&apos;<b>t</b>',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['salt'],
-        output: '<b>salt</b>&amp;pepper',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['salt', 'alt'],
-        output: '<b>salt</b>&amp;pepper',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['pepper'],
-        output: 'salt&amp;<b>pepper</b>',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['salt', 'pepper'],
-        output: '<b>salt</b>&amp;<b>pepper</b>',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['t', 'p'],
-        output: 'sal<b>t</b>&amp;<b>p</b>e<b>p</b><b>p</b>er',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['t', '&', 'p'],
-        output: 'sal<b>t</b><b>&amp;</b><b>p</b>e<b>p</b><b>p</b>er',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['e'],
-        output: 'salt&amp;p<b>e</b>pp<b>e</b>r',
-    },
-    {
-        input: 'salt&pepper',
-        terms: ['&a', '&am', '&amp', '&amp;'],
-        output: 'salt&amp;pepper',
-    },
-    {
-        input: '&&&&&',
-        terms: ['a'],
-        output: '&amp;&amp;&amp;&amp;&amp;',
-    },
-    {
-        input: '&;&;&;&;&;',
-        terms: ['a'],
-        output: '&amp;;&amp;;&amp;;&amp;;&amp;;',
-    },
-    {
-        input: '&;&;&;&;&;',
-        terms: [';'],
-        output: '&amp;<b>;</b>&amp;<b>;</b>&amp;<b>;</b>&amp;<b>;</b>&amp;<b>;</b>',
-    },
-    {
-        input: '&amp;',
-        terms: ['a'],
-        output: '&amp;<b>a</b>mp;',
-    },
-];
+describe('Highlighter', () => {
+    const tests = [
+        {
+            input: 'abc cba',
+            terms: null,
+            output: 'abc cba',
+        },
+        {
+            input: 'abc cba',
+            terms: [],
+            output: 'abc cba',
+        },
+        {
+            input: 'abc cba',
+            terms: [''],
+            output: 'abc cba',
+        },
+        {
+            input: 'abc cba',
+            terms: ['a'],
+            output: '<b>a</b>bc cb<b>a</b>',
+        },
+        {
+            input: 'abc cba',
+            terms: ['a', 'a'],
+            output: '<b>a</b>bc cb<b>a</b>',
+        },
+        {
+            input: 'CaSe InSenSiTiVe',
+            terms: ['cas', 'sens'],
+            output: '<b>CaS</b>e In<b>SenS</b>iTiVe',
+        },
+        {
+            input: 'This contains the < character',
+            terms: null,
+            output: 'This contains the &lt; character',
+        },
+        {
+            input: 'Don\'t',
+            terms: ['t'],
+            output: 'Don&apos;<b>t</b>',
+        },
+        {
+            input: 'Don\'t',
+            terms: ['n\'t'],
+            output: 'Do<b>n&apos;t</b>',
+        },
+        {
+            input: 'Don\'t',
+            terms: ['o', 't'],
+            output: 'D<b>o</b>n&apos;<b>t</b>',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['salt'],
+            output: '<b>salt</b>&amp;pepper',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['salt', 'alt'],
+            output: '<b>salt</b>&amp;pepper',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['pepper'],
+            output: 'salt&amp;<b>pepper</b>',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['salt', 'pepper'],
+            output: '<b>salt</b>&amp;<b>pepper</b>',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['t', 'p'],
+            output: 'sal<b>t</b>&amp;<b>p</b>e<b>p</b><b>p</b>er',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['t', '&', 'p'],
+            output: 'sal<b>t</b><b>&amp;</b><b>p</b>e<b>p</b><b>p</b>er',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['e'],
+            output: 'salt&amp;p<b>e</b>pp<b>e</b>r',
+        },
+        {
+            input: 'salt&pepper',
+            terms: ['&a', '&am', '&amp', '&amp;'],
+            output: 'salt&amp;pepper',
+        },
+        {
+            input: '&&&&&',
+            terms: ['a'],
+            output: '&amp;&amp;&amp;&amp;&amp;',
+        },
+        {
+            input: '&;&;&;&;&;',
+            terms: ['a'],
+            output: '&amp;;&amp;;&amp;;&amp;;&amp;;',
+        },
+        {
+            input: '&;&;&;&;&;',
+            terms: [';'],
+            output: '&amp;<b>;</b>&amp;<b>;</b>&amp;<b>;</b>&amp;<b>;</b>&amp;<b>;</b>',
+        },
+        {
+            input: '&amp;',
+            terms: ['a'],
+            output: '&amp;<b>a</b>mp;',
+        },
+    ];
 
-try {
-    for (let i = 0; i < tests.length; i++) {
-        let highlighter = new Util.Highlighter(tests[i].terms);
-        let output = highlighter.highlight(tests[i].input);
+    for (const test of tests) {
+        const {terms, input, output: expected} = test;
 
-        JsUnit.assertEquals(`Test ${i + 1} highlight ` +
-            `"${tests[i].terms}" in "${tests[i].input}"`,
-        output, tests[i].output);
+        it(`highlights ${JSON.stringify(terms)} in "${input}"`, () => {
+            const highlighter = new Highlighter(terms);
+            const output = highlighter.highlight(input);
 
-        let parsed = false;
-        try {
-            Pango.parse_markup(output, -1, '');
-            parsed = true;
-        } catch (e) {}
-        JsUnit.assertEquals(`Test ${i + 1} is valid markup`, true, parsed);
+            expect(output).toEqual(expected);
+            expect(() => Pango.parse_markup(output, -1, '')).not.toThrow();
+        });
     }
-} catch (e) {
-    if (typeof  e.isJsUnitException != 'undefined' &&
-        e.isJsUnitException) {
-        if (e.comment)
-            log(`Error in: ${e.comment}`);
-    }
-    throw e;
-}
+});